import React,{Component} from 'react'
import {Link,browserHistory} from 'react-router'
import * as pub from '../../config/public';
import {getSelectessay,submitEssSh} from '../../config/fetch'
import { Spin,message } from 'antd'
class ArticleDetail extends Component {
	constructor(props) {
		super(props)
		this.state={
			recordId:'',
			article:{},
			essayPhotos:[]
		}
	}
    componentWillMount() {
	   pub.loading(this,true);
		getSelectessay({essayId:this.props.params.id}).then((data) => {
              this.setState({
				article: data.essay,
				essayPhotos:data.essay.essayPhotos?data.essay.essayPhotos:[]
			  });
			  pub.loading(this,false);
		},(res)=>{
         pub.loading(this,false);
		 pub.reject(res);
		})
	}
	submitSH(){
		submitEssSh({essayId:this.props.params.id}).then((data)=>{
            if (data.result === 'RC100') {
				pub.jumpHistory.push('/admin/ArticleManage');
			} else {
				message.error(data.errMsg, 3);
			}
		},(res)=>{
		 pub.reject(res);
		})
	}
	render(){
		let article=this.state.article;
		return(
			<div className="container">
		       <div className="wrapper bg-F0F4F6">
		       	<div className="layout pad-t-20" style={{width:'100%'}}>
					<Spin spinning={this.state.loading} tip="加载列表中...">   
		       		<div className="row bg-FFFFFF">
		       			<div className="article-details">
		       				<div className="title" style={{ width:'100%',textOverflow: 'ellipsis'}}>{article.essayTitle}</div>
		       				<div className="like-read-time">
		       					<span><i className="icon-heart-empty"></i>{article.sumCollection}</span>
		       					<span><i className="icon-eye-open"></i>{article.sumClick}</span>
										<span><i className="icon-time"></i>&nbsp;{article.userRealName}&nbsp;&nbsp;{pub.formatTimestamp(article.createTime)}</span>
		       				</div>
		       				<div className="line"></div>
		       				<div className="content">
								   <pre style={{whiteSpace: 'pre-wrap',wordWrap: 'break-word'}}>{article.essayNote}</pre>
		       					  {
									   this.state.essayPhotos.map((item,index)=>{
										   return(
                                                <img key={index}  src={pub.getFile(item.essayPhotoPath)} alt='test' style={{maxWidth: '300px',minWidth: '250px',height:'250px',margin:'20px auto'}}/>
										   )
									   })
								   }
		       				</div>
									<div className="topic mar-b-20">
										{
											article.checkState === '4' ? null :
												<dl>
													<dt style={{fontWeight:"normal"}}>审核意见</dt>
													<dd><textarea disabled={true} value={article.auditOpinion} ref="checkReason" onKeyUp={this.numberInputs}></textarea></dd>
												</dl>
										}

									</div>
		       				<div className="row text-right">
		       					<Link to="/admin/ArticleManage" className="back-list">返回文章列表&gt;</Link>
		       				</div>
							   <div className="pop-btn1">
								   {
									   article.checkState==='4'?
									   <a className="btn btn-blue" onClick={()=>this.submitSH()}>提交审核</a>:null
								   }
						       </div>	
		       			</div>
		       		</div>
				  </Spin>
		       	</div>
		       </div>
			</div>
			)
	}
}
export default ArticleDetail;